import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';
import { ConfigEnum } from '/@/enums/httpEnum'


enum Api {
  list = "/food-service/storeTag/listStoreTag",
  save = "/food-service/storeTag/saveStoreTag",
  edit = "/food-service/storeTag/updateStoreTag",
  delete = "/food-service/storeTag/deleteStoreTag",
  deleteBatch = "/food-service/storeTag/batchDeleteStoreTag",
}

/**
 * 查询列表
 * @param params
 */
export const listStoreTag = (params) => {
  return defHttp.get({url: Api.list, params});
}

/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdate = (params, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}

/**
 * 删除
 * @param params
 */
export const deleteStoreTag = (params, handleSuccess) => {
  const headers = {}
  headers[ConfigEnum.TENANT_ID] = params.tenantId
  return defHttp.delete({url: Api.delete, data: params, headers}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 */
export const batchDeleteStoreTag = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
